package com.certificationManager.client.util;

import com.certificationManager.client.bean.UserBean;
import com.certificationManager.client.service.UserService;
import com.certificationManager.client.service.UserServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class UserUtils {

	/** Services */
	private final UserServiceAsync userService = GWT.create(UserService.class);
	
	private static final UserUtils singleton = new UserUtils();
	
	private UserUtils() {}
	
	public static UserUtils getInstance() {return singleton;}
	
	public UserBean getCurrentUser() {
		
		String userId = Cookies.getCookie(CookieUtils.USERID_COOKIE);
		
		userService.getUser(userId, new AsyncCallback<UserBean>() {
			
			@Override
			public void onSuccess(UserBean result) {
				// TODO Auto-generated method stub
				System.out.println("success");
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				System.out.println("failure");
			}
		});
		
		return new UserBean();
		
	}
	
	public void disconnect() {
		Cookies.removeCookie(CookieUtils.USERID_COOKIE);
	}
	
	
}
